﻿<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI.Widgets" TagPrefix="widgets" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI.Dialogs" TagPrefix="dialogs" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<script type="text/javascript">
    Type.registerNamespace("Telerik.Web.UI.Editor.DialogControls");
    Type.registerNamespace("Telerik.Web.UI.WindowBehaviors");

    Telerik.Web.UI.Editor.DialogControls.FileBrowser = function (element) {
        Telerik.Web.UI.Editor.DialogControls.FileBrowser.initializeBase(this, [element]);
    };

    Telerik.Web.UI.Editor.DialogControls.FileBrowser.prototype = {
        initialize: function () {
            this.set_insertButton(window.$get("InsertButton"));
            this.set_cancelButton(window.$get("CancelButton"));

            var previewer = this.get_previewerType();
            var previewerType = eval("Telerik.Web.UI.Widgets." + previewer);
            window.$create(previewerType, { "browser": this }, null, null, window.$get(previewer));
            this.set_filePreviewer(window.$find(previewer));
            this.set_fileBrowser(window.$find("RadFileExplorer1"));

            Telerik.Web.UI.Editor.DialogControls.FileBrowser.callBaseMethod(this, 'initialize');
        },

        dispose: function () {
            Telerik.Web.UI.Editor.DialogControls.FileBrowser.callBaseMethod(this, 'dispose');
            this._insertButton = null;
            this._cancelButton = null;
        }
    };

    //    editor.showExternalDialog('SP/MultiUpload.aspx', null, 800, 600, null, null, 'Upload nhiều ảnh', true, window.Telerik.Web.UI.WindowBehaviors.Close + window.Telerik.Web.UI.WindowBehaviors.Move, true, true);

    function collapseNodes() {
        var explorer = window.$find("RadFileExplorer1");
        var tree = explorer.get_tree();
        var nodes = tree.get_allNodes();
        nodes.forEach(function (node) {
            if (node.get_expanded())
                node.set_expanded(false);
        });
    }
    
    function openMultiUpload() {
        var argument = {};

        //a callback function to be executed when the RadWindow is closed
        var callbackFunction = function (sender, args) {
            //http://www.telerik.com/help/aspnet-ajax/fileexplorer-client-side.html
            //http://www.telerik.com/community/forums/aspnet-ajax/file-explorer/invoke-fileexplorer-commands-from-custom-button.aspx
            var oExplorer = window.$find("<%= RadFileExplorer1.ClientID %>");
//            oExplorer.get_treeUpdatePanel().ajaxRequest('_');
            oExplorer.refresh();
//            var uploadItem = oExplorer.get_gridContextMenu().findItemByValue("Upload"); // use the contextmenu's Upload command
//            uploadItem.click();
        };
        //get reference to the dialogOpener
        var dialogOpener = Telerik.Web.UI.Dialogs.CommonDialogScript.get_windowReference().get_dialogOpener();
        
        //open the dialog window 
        dialogOpener.openUrl('SP/MultiUpload.aspx', argument, 800, 600, callbackFunction, null, "Upload nhiều ảnh", true, 36, false, true);
    }
    
    
    function OnClientFilter(sender, eventArgs) {
    }

    Telerik.Web.UI.Editor.DialogControls.FileBrowser.registerClass('Telerik.Web.UI.Editor.DialogControls.FileBrowser', Telerik.Web.UI.Widgets.FileManager);
</script>
<style type="text/css">
    .RadFileExplorer .RadGrid .rgPager .rgWrap
    {
        float: none;
    }
    .RadFileExplorer .RadGrid .rgPager .RadSlider
    {
        float: none;
    }
    .RadFileExplorer .RadGrid .rgPager .rgSliderLabel
    {
        float: left;
    }
    .RadFileExplorer .RadGrid .rgPager .rgInfoPart
    {
        text-align: right;
    }
</style>


<table class="reDialog ManagerDialog NoMarginDialog" border="0" cellpadding="0" cellspacing="0"
    style="width: 100%;">
    <tr id="listRow">
        <td rowspan="2" class="FileExplorerPlaceholder">
            <asp:Button Text="Upload nhiều ảnh" ID="Button2" runat="server" OnClientClick="openMultiUpload(); return false;" />
            <telerik:RadFileExplorer ID="RadFileExplorer1" Height="450px" Width="400px" TreePaneWidth="150px"
                runat="Server" EnableOpenFile="false" EnableFilterTextBox="true" OnClientFilter="OnClientFilter"
                FilterTextBoxLabel="Lọc theo tên" AllowPaging="true" PageSize="100" />
            <asp:Button Text="Collapse Nodes" ID="Button1" runat="server" OnClientClick="collapseNodes(); return false;" />
        </td>
        <td rowspan="2" class="DialogSeparator">
            &nbsp;
        </td>
        <td style="width: 100%; vertical-align: top; padding: 0; height: 412px;">
            <asp:PlaceHolder ID="PreviewerPlaceHolder" runat="server" />
        </td>
    </tr>
    <tr>
        <td class="reBottomcell">
            <table border="0" cellpadding="0" cellspacing="0" class="reConfirmCancelButtonsTbl">
                <tr>
                    <td>
                        <button type="button" id="InsertButton">
                            <script type="text/javascript">
                                setInnerHtml("InsertButton", localization["Insert"]);
                            </script>
                        </button>
                    </td>
                    <td class="reRightMostCell">
                        <button type="button" id="CancelButton">
                            <script type="text/javascript">
                                setInnerHtml("CancelButton", localization["Cancel"]);
                            </script>
                        </button>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

<script runat="server" type="text/C#">  
  
    //protected void Page_Load(object sender, System.EventArgs args)
    //{
    //    RadToolBarButton adminLogin = new RadToolBarButton("Administration");
    //    adminLogin.Value = "admincommand";
    //    adminLogin.CssClass = "adminLoginStyleClass";
    //    adminLogin.OuterCssClass = "rightButton";
    //    adminLogin.Attributes.Add("onclick", "window.location.href='Admin'");
    //    RadFileExplorer1.ToolBar.Items.Add(adminLogin);
    //}
</script>